package com.cwj.web.controller;

import com.cwj.service.CourseInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import common.entity.course;
import common.entity.course_video;
import common.entity.teacher;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping({"/course"})
public class CourseInfoController {
    @Resource
    CourseInfo courseInfo;
    @Resource
    ObjectMapper objectMapper;
    @PostMapping({"/Synopsis/{id}/{name}","/Overview/{id}/{name}"})
    public course getCourseMsg(@PathVariable("id") Integer id, @PathVariable("name") String name){
        return courseInfo.getCourseMsg(id,name);
    }
    @PostMapping("/GetTeacherList/{id}/{name}")
    public Map<String,teacher> getCourseTeacherList(@PathVariable("id") Integer id, @PathVariable("name") String name) throws Exception {
        return courseInfo.getCourseTeacherList(id,name);
    }
    @PostMapping({"/video/{id}/{name}/{count}"})
    public List<course_video> getCourse_video(@PathVariable Integer id ,@PathVariable String name,@PathVariable Integer count){
        List<course_video> videos = courseInfo.getCourse_video(id, name, count);
        Collections.sort(videos);
        return videos;
    }
    @PostMapping("/video/getTeacherList/{course_id}/{id}")
    public List<teacher> getCourse_videoTeacher(@PathVariable Integer course_id,@PathVariable String id){
        List<teacher> teacherList = courseInfo.getCourse_videoTeacher(course_id, id);
        Collections.shuffle(teacherList);
        return teacherList;
    }
    @PostMapping("/video/FindPageCount/{course_id}/{course_name}/{size}")
    public Integer FindPageCount(@PathVariable Integer course_id,@PathVariable String course_name,@PathVariable Integer size){
        return courseInfo.FindPageCount(course_id, course_name, size);
    }
    @PostMapping("/video/getCourse_videoByPage/{course_id}/{page}/{size}")
    public List<course_video> getCourse_videoByPage(@PathVariable Integer course_id,@PathVariable Integer page,@PathVariable Integer size){
        List<course_video> videos = courseInfo.getCourse_videoByPage(course_id, page, size);
        return videos;
    }
    @PostMapping("/video/findCourse_videoPict/{course_id}/{id}")
    public String findCourse_videoPict(@PathVariable Integer course_id,@PathVariable String id) throws Exception {
        String course_videoPict = courseInfo.findCourse_videoPict(course_id, id);
//        System.out.println(course_videoPict);
        return course_videoPict;
    }
    @PostMapping("/video/getCourse_videoCatalogue/{course_id}/{grade}")
    public List<String> getCourse_videoCatalogue(@PathVariable Integer course_id,@PathVariable Integer grade){
        return null;
    }
    @PostMapping("/video/getMaxGrade/{course_id}")
    public int[] getMaxGrade(@PathVariable Integer course_id){
        //        System.out.println(Arrays.toString(maxGrade));
        return courseInfo.getMaxGrade(course_id);
    }
}
